package com.hm.manage.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hm.common.annotation.Log;
import com.hm.common.core.controller.BaseController;
import com.hm.common.core.domain.AjaxResult;
import com.hm.common.enums.BusinessType;
import com.hm.manage.domain.Hardserver;
import com.hm.manage.service.IHardserverService;
import com.hm.common.utils.poi.ExcelUtil;
import com.hm.common.core.page.TableDataInfo;

/**
 * 服务器Controller
 * 
 * @author hm
 * @date 2025-04-01
 */
@Slf4j
@RestController
@RequestMapping("/manage/hardserver")
public class HardserverController extends BaseController
{
    @Autowired
    private IHardserverService hardserverService;

    /**
     * 查询服务器列表
     */
    @PreAuthorize("@ss.hasPermi('manage:hardserver:list')")
    @GetMapping("/list")
    public TableDataInfo list(Hardserver hardserver)
    {
        startPage();
        List<Hardserver> list = hardserverService.selectHardserverList(hardserver);
        for (Hardserver hardserver1 : list) {
            //log.info("-------查询的内容--{}-----",hardserver1.toString());
        }
        return getDataTable(list);
    }

    /**
     * 导出服务器列表
     */
    @PreAuthorize("@ss.hasPermi('manage:hardserver:export')")
    @Log(title = "服务器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hardserver hardserver)
    {
        List<Hardserver> list = hardserverService.selectHardserverList(hardserver);
        ExcelUtil<Hardserver> util = new ExcelUtil<Hardserver>(Hardserver.class);
        util.exportExcel(response, list, "服务器数据");
    }

    /**
     * 获取服务器详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:hardserver:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hardserverService.selectHardserverById(id));
    }

    /**
     * 新增服务器
     */
    @PreAuthorize("@ss.hasPermi('manage:hardserver:add')")
    @Log(title = "服务器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hardserver hardserver)
    {
        //log.info("-------新增的内容--{}-----",hardserver.toString());
        return toAjax(hardserverService.insertHardserver(hardserver));
    }

    /**
     * 修改服务器
     */
    @PreAuthorize("@ss.hasPermi('manage:hardserver:edit')")
    @Log(title = "服务器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hardserver hardserver)
    {
        //log.info("-------修改的内容--{}-----",hardserver.toString());
        return toAjax(hardserverService.updateHardserver(hardserver));
    }

    /**
     * 删除服务器
     */
    @PreAuthorize("@ss.hasPermi('manage:hardserver:remove')")
    @Log(title = "服务器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hardserverService.deleteHardserverByIds(ids));
    }

    /**
     * 获取服务器信息
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('manage:hardserver:edit')")
    @Log(title = "服务器", businessType = BusinessType.UPDATE)
    @GetMapping("/getServerInfo/{id}")
    public AjaxResult getServerInfo(@PathVariable Long id){
        //log.info("-------获取服务器信息的内容--{}-----",id);
        return success(hardserverService.getServerInfo(id));
    }
}
